package com.example.service.impl;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.poi.ss.usermodel.CellType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.dao.ProjectInfoMapper;
import com.example.dao.UxJbcardMapper;
import com.example.dao.UxenglstMapper;
import com.example.dao.UxpmStckMapper;
import com.example.dao.UxpmtomMapper;
import com.example.dao.UxtpMapper;
import com.example.dao.WeldingListMapper;
import com.example.entity.DrawingMaterial;
import com.example.entity.Material2;
import com.example.entity.SchedulePlanEngineering;
import com.example.service.AutoCbsServer;
import sun.security.tools.keytool.Main;

@Service
public class AutoCbsServerImpl extends Util implements AutoCbsServer {

	@Autowired
	AnalyzeServerImpl AnalyzeServer;
	@Autowired
	private UxpmStckMapper uxpmStck;
	@Autowired
	private UxenglstMapper uxenglstMapper;
	@Autowired
	private UxJbcardMapper UxJbcardMapper;
	@Autowired
	private ProjectInfoMapper projectInfoMapper;
	@Autowired
	private UxtpMapper uxtpMapper;
	@Autowired
	private WeldingListMapper weldingListMapper;

	/**
	 * 解析AR 舾装专业 生成物料数据生成 图纸清单
	 */
	@Override
	public void AnalyzeMTRExcelAR() throws IOException {
		AnalyzeServerImpl	analyzeServerImpl = new AnalyzeServerImpl();

		//将execl表里面的数据解析出来
		List<List<Map<String, String>>> datas = analyzeServerImpl.AnalyzeExcelAR("E:/普华宇鹏/物料表格/数据追踪表9.16--新.xlsx"); // 相关表格中所有数据信息
		Set<Map<String, String>> shopDrawings = new HashSet<Map<String, String>>();// 图纸信息
		Set<Map<String, String>> materials = new HashSet<Map<String, String>>(); // 母材信息
		Map<String, String> material = null;

		//图纸文件关系表
		Map<String, DrawingMaterial> drawingMaterialsMap = new HashMap<String, DrawingMaterial>();
		Set<Material2> material2s = new HashSet<Material2>();
		String jobNo = null;
		//把execl表里面每一行的数据循环出来
		for (Map<String, String> index : datas.get(0)) { // 行级循环

			if (jobNo == null) {
				jobNo = index.get("jobNo");
			}

			// 母材信息塞入
			if (index.get("materialCode") != null && !index.get("materialCode").equals("NA")
					&& !index.get("materialCode").equals(" ")) {
				boolean is = true;
				for (Map<String, String> materialsIndex : materials) {
					if (materialsIndex.get("materialCode").equals(index.get("materialCode"))) {
						is = false;
					}

				}
				if (is) {

					//把物料表的信息解析出来，存储到oracle系统中
					material = new HashMap<String, String>();
					material.put("materialCode", index.get("materialCode"));//物料编码
					material.put("OldMaterialPartCode", index.get("materialCoding"));//旧物料编码
					material.put("Discipline",index.get("discipline"));//专业
					material.put("grade", index.get("grade")); // 材质
					material.put("unit", index.get("unit"));// 单位
					materials.add(material);
				}
			}

			//加设图数据信息存入
			if (index.get("shopDrawingNo") != null && !index.get("shopDrawingNo").equals(" ")&& !index.get("shopDrawingNo").equals("")) {
					Map<String, String> shopMap = new HashMap<String, String>();

				/**
				 * shopDrawingNo: oracle系统中的标准
				 * index.get("shopDrawingNo")：自己定义的
				 */
					shopMap.put("shopDrawingNo", index.get("shopDrawingNo") );//加设图编号
					shopMap.put("shopDrawingRev", index.get("shopDrawingRev"));//加设图版本
					shopMap.put("workPackageNo", index.get("workPackageNo"));//工作包编码
					shopMap.put("moduleName", index.get("moduleName"));//
                    shopDrawings.add(shopMap);


                String shopDrawingNo= index.get("shopDrawingNo");
				DrawingMaterial data = this.setDrawingMaterialAR(index, shopDrawingNo, index.get("shopDrawingRev"),
						"AR", "shopDrawing");//shopDrawingRev  加设图纸版本   shopDrawingNo  加设图纸编号
				if (drawingMaterialsMap.get(shopDrawingNo + index.get("shopDrawingRev")) == null) {
					drawingMaterialsMap.put(shopDrawingNo + index.get("shopDrawingRev"), data);
				} else {
					drawingMaterialsMap.get(shopDrawingNo + index.get("shopDrawingRev")).getMaterials()
							.addAll(data.getMaterials());
				}
			}
		}


		//根据项目编号查询项目id
		Integer projectNumber = projectInfoMapper.select_ProjectNumber(jobNo);


		this.insertMaterials(materials, "AR", "bulk", projectNumber); // 插入母材物料



		// 图纸关联物料信息 // 插入物料与图纸的对应关系
		this.insertdrawingMaterials(drawingMaterialsMap, "AR", projectNumber);

		System.out.println("============"+drawingMaterialsMap);
		// 插入物料与图纸的对应关系
		// 提交s
		for(Map<String, String> index:shopDrawings){
			System.out.println(index);
		}

		//图纸去重  避免execl表格里面重复的数据
        List<SchedulePlanEngineering> setemps = this.deweightDrawing(shopDrawings, null,
                null, "AR", jobNo);// 图纸去重

        this.insertDrawing(setemps, jobNo); // 插入图纸
	}

	/**
	 * 解析HVAC 通风专业 生成物料数据生成 图纸清单
	 */
	@Override
	public void AnalyzeMTRExcelHVAC() throws IOException {
		AnalyzeServerImpl AnalyzeImpl = new AnalyzeServerImpl();
		List<List<Map<String, String>>> list = AnalyzeImpl
				.AnalyzeExcelHVAC("F:/test/物料表格/HVAC/TBJN0149-MERO2-TS130-HVAC.xlsx");

		Set<Map<String, String>> materials = new HashSet<Map<String, String>>(); // 母材信息
		Map<String, String> material = null;
		Set<Map<String, String>> setdata = new HashSet<Map<String, String>>();
		Map<String, DrawingMaterial> drawingMaterialsMap = new HashMap<String, DrawingMaterial>();
		Set<Material2> material2s = new HashSet<Material2>();
		String jobNo = null;

		for (Map<String, String> map : list.get(0)) {
			if (jobNo == null) {
				jobNo = map.get("jobNo");
			}
			if (map.get("materialCode") != null && !map.get("materialCode").equals("NA")
					&& !map.get("materialCode").equals(" ")) {
				// 母材信息塞入
				boolean is = true;
				for (Map<String, String> materialsIndex : materials) {
					if (materialsIndex.get("materialCode").equals(map.get("materialCode"))) {
						is = false;
					}

				}
				if (is) {
					material = new HashMap<String, String>();
					material.put("materialCode", map.get("materialCode"));
					material.put("OldMaterialPartCode", map.get("materialCode2"));
					material.put("grade", map.get("grade")); // 材质
					material.put("unit", map.get("unit"));// 单位
					materials.add(material);
				}
			}

			if (map.get("shopDrawingNo") != null) {

				if (map.get("shopDrawingNo").length() > 32) {
					String[] ShopDrawingNos = map.get("shopDrawingNo").split("/");
					for (int i = 0; i < ShopDrawingNos.length; i++) {
						Map<String, String> shopMap = new HashMap<String, String>();
						if (ShopDrawingNos[i].length() < 32) {
							String shopDrawingNo = ShopDrawingNos[0].substring(0,
									ShopDrawingNos[0].length() - ShopDrawingNos[i].length()) + ShopDrawingNos[i];

							shopMap.put("shopDrawingNo", shopDrawingNo);
							shopMap.put("workPackageNo", map.get("workPackageNo"));
							shopMap.put("shopDrawingRev", map.get("shopDrawingRev"));
							shopMap.put("projectName", map.get("projectName"));
							shopMap.put("moduleName", map.get("moduleName"));
							setdata.add(shopMap);
							DrawingMaterial data = this.setDrawingMaterial(map, shopDrawingNo,
									map.get("shopDrawingRev"), "HVAC", "shopDrawingNo");

							if (drawingMaterialsMap.get(shopDrawingNo + map.get("shopDrawingRev")) == null) {
								drawingMaterialsMap.put(shopDrawingNo + map.get("shopDrawingRev"), data);
							} else {
								drawingMaterialsMap.get(shopDrawingNo + map.get("shopDrawingRev")).getMaterials()
										.addAll(data.getMaterials());
							}

						} else {

							shopMap.put("shopDrawingNo", ShopDrawingNos[i]);
							shopMap.put("workPackageNo", map.get("workPackageNo"));
							shopMap.put("shopDrawingRev", map.get("shopDrawingRev"));
							shopMap.put("projectName", map.get("projectName"));
							shopMap.put("moduleName", map.get("moduleName"));
							setdata.add(shopMap);

							DrawingMaterial data = this.setDrawingMaterial(map, ShopDrawingNos[i],
									map.get("shopDrawingRev"), "HVAC", "shopDrawingNo");

							if (drawingMaterialsMap.get(ShopDrawingNos[i] + map.get("shopDrawingRev")) == null) {
								drawingMaterialsMap.put(ShopDrawingNos[i] + map.get("shopDrawingRev"), data);
							} else {
								drawingMaterialsMap.get(ShopDrawingNos[i] + map.get("shopDrawingRev")).getMaterials()
										.addAll(data.getMaterials());
							}

						}
					}
				}
			}

		}
		Integer projectNumber = projectInfoMapper.select_ProjectNumber(jobNo);
		this.insertMaterials(materials, "HVAC", "bulk", projectNumber); // 插入母材物料

		// 插入物料与图纸的对应关系
		this.insertdrawingMaterials(drawingMaterialsMap, "HVAC", projectNumber);

		// List<SchedulePlanEngineering> setemps = this.deweightDrawing(uxenglstMapper,
		// setdata, null, null, "HVAC");

		// this.insertDrawing(setemps); // 插入图纸

	}

	/**
	 * 解析ST 结构专业物料追踪表
	 */
	@Override
	public void AnalyzeMTRExcelST() throws IOException {

		List<Map<String, String>> projectInfoMaps = projectInfoMapper.select_ProjectID_Number(); // 查找出所有项目

		for (Map<String, String> projectInfoMap : projectInfoMaps) { // 遍历项目

			Object object = projectInfoMap.get("PID");
			int projectId = Integer.parseInt(String.valueOf(object));

			Set<Map<String, String>> shopDrawings = new HashSet<Map<String, String>>();// 加设图纸
			Set<Map<String, String>> nestingDrawings = new HashSet<Map<String, String>>();// 套料图
			Set<Map<String, String>> fabricationDrawings = new HashSet<Map<String, String>>();// 构件图
			Set<Map<String, String>> materials = new HashSet<Map<String, String>>(); // 母材信息
			Set<Map<String, String>> partss = new HashSet<Map<String, String>>();// 零件
			Set<Map<String, String>> remnantParts = new HashSet<Map<String, String>>();// 余料
			Set<Map<String, String>> assemblyFabricationDetails = new HashSet<Map<String, String>>();// 构件
			Map<String, String> shopDrawingMap = null; // 套料图
			Map<String, String> nestingDrawingMap = null; // 加设图
			Map<String, String> fabricationDrawingMap = null; // 构件图
			Map<String, String> material = null;
			Map<String, String> parts = null;
			Map<String, String> remnantPart = null;
			Map<String, String> assemblyFabricationDetail = null;
			Map<String, DrawingMaterial> drawingMaterialsMap = new HashMap<String, DrawingMaterial>();
			String jobNo = null;
			// String path = "F:/test/ST2 - 副本";
			// String path="F:/test/ST/Bacalhau FPSO Topside";

			List<String> filePaths = this.inquire_ProjectMTRFilePath(projectId, "ST");

			for (String filePath : filePaths) {
				System.err.println(filePath);
				List<List<Map<String, String>>> list = AnalyzeServer.AnalyzeExcelST(filePath);
				for (Map<String, String> index : list.get(0)) {
					if (jobNo == null) {
						jobNo = index.get("jobNo");
					}
					// 母材信息塞入
					if (index.get("materialCode") != null && !index.get("materialCode").equals("NA")
							&& !index.get("materialCode").equals(" ")) {
						material = new HashMap<String, String>();
						material.put("materialCode", index.get("materialCode"));
						material.put("OldMaterialPartCode", index.get("materialCode2"));
						material.put("grade", index.get("grade")); // 材质
						material.put("unit", index.get("unit"));// 单位
						materials.add(material);

					}
					// 零件信息
					if (index.get("partNo") != null && !index.get("partNo").equals("NA")
							&& !index.get("partNo").equals(" ")) {
						parts = new HashMap<String, String>();
						parts.put("partNo", index.get("partNo"));// 零件编号
						parts.put("partGUIDNo", index.get("partGUIDNo"));// 零件编号
						parts.put("partName", index.get("partName"));// 零件名称
						parts.put("steelType", index.get("steelType")); // 零件类型
						parts.put("structureType", index.get("structureType")); // 零件结构类型
						parts.put("areaofPart", index.get("areaofPart")); // 零件区域
						parts.put("levelNo", index.get("levelNo")); // 零件层级
						parts.put("workPackageNo", index.get("workPackageNo"));// 工作包
						parts.put("partProfileName", index.get("partProfileName")); // 零件规格名称
						parts.put("partProfile", index.get("partProfile")); // 零件规格
						parts.put("netSingleLength", index.get("netSingleLength")); // 零件净长度
						parts.put("netSingleWidth", index.get("netSingleWidth")); // 零件宽度
						parts.put("unitWeight", index.get("unitWeight")); // 零件单重量
						parts.put("netSingleWeight", index.get("netSingleWeight")); // 零件单净重
						parts.put("netTotalWeight", index.get("netTotalWeight")); // 零件总净重
						parts.put("grossSingleWeight", index.get("grossSingleWeight")); // 零件单毛重
						parts.put("grossTotalWeight", index.get("grossTotalWeight")); // 零件总毛重
						parts.put("netArea", index.get("netArea")); // 零件总毛重
						parts.put("unit", index.get("unit"));// 计量单位
						parts.put("grade", index.get("grade")); // 材质
						parts.put("discipline", "ST"); // 材质
						parts.put("partProfile", index.get("partProfile")); // 零件规格
						parts.put("materialCode", index.get("materialCode"));// 母材编号
						parts.put("materialCode2", index.get("materialCode2"));// 母材编号
						parts.put("assemblyFabricationDetailNo", index.get("assemblyFabricationDetailNo"));// 构件编码
																											// 也是预制图版本
						parts.put("assemblyFabricationDetailRev", index.get("shopDrawingRev")); // 版本
						parts.put("nestingDrawingNo", index.get("nestingDrawingNo")); // 套料图
						parts.put("nestingDrawingRev", index.get("nestingDrawingRev"));// 套料图版本
						partss.add(parts);

					}
					// 余料
					if (index.get("remnantPartNo") != null && !index.get("remnantPartNo").equals("")
							&& !index.get("remnantPartNo").equals("整料") && !index.get("remnantPartNo").equals("NA")) {
						remnantPart = new HashMap<String, String>();
						remnantPart.put("remnantPartNo", index.get("remnantPartNo"));
						remnantPart.put("unit", index.get("unit"));// 计量单位
						remnantPart.put("grade", index.get("grade")); // 材质
						remnantPart.put("materialCode", index.get("materialCode"));// 母材编号
						remnantParts.add(remnantPart);
					}
					// 构件信息
					if (index.get("assemblyFabricationDetailNo") != null
							&& !index.get("assemblyFabricationDetailNo").equals("")
							&& !index.get("assemblyFabricationDetailNo").equals("NA")
							&& index.get("assemblyFabricationDetailNo").length() >= 10
							&& !index.get("shopDrawingRev").equals(null)) {

						assemblyFabricationDetail = new HashMap<String, String>();
						assemblyFabricationDetail.put("assemblyFabricationDetailNo",
								index.get("assemblyFabricationDetailNo"));// 构件编码
						assemblyFabricationDetails.add(assemblyFabricationDetail);

						fabricationDrawingMap = new HashMap<String, String>();
						fabricationDrawingMap.put("FabricationDrawingNo", index.get("assemblyFabricationDetailNo"));
						fabricationDrawingMap.put("FabricationDrawingNoRev", index.get("shopDrawingRev"));
						fabricationDrawingMap.put("fatherDrawingNo", index.get("shopDrawingNo"));
						fabricationDrawingMap.put("fatheDrawingREV", index.get("shopDrawingRev"));
						fabricationDrawingMap.put("moduleName", index.get("moduleName"));
						fabricationDrawingMap.put("workPackageNo", index.get("workPackageNo"));
						String JobcardInstallNo = index.get("moduleName") + "-" + index.get("workPackageNo") + "-"
								+ index.get("assemblyFabricationDetailNo").substring(0, 10);
						fabricationDrawingMap.put("JobcardInstallNo", JobcardInstallNo);
						fabricationDrawings.add(fabricationDrawingMap);

						DrawingMaterial data = this.setDrawingMaterial(index, index.get("assemblyFabricationDetailNo"),
								index.get("shopDrawingRev"), "ST", "fatherDrawing");
						if (drawingMaterialsMap
								.get(index.get("assemblyFabricationDetailNo") + index.get("shopDrawingRev")) == null) {
							drawingMaterialsMap
									.put(index.get("assemblyFabricationDetailNo") + index.get("shopDrawingRev"), data);
						} else {
							drawingMaterialsMap
									.get(index.get("assemblyFabricationDetailNo") + index.get("shopDrawingRev"))
									.getMaterials().addAll(data.getMaterials());
						}

					}

					if (index.get("shopDrawingNo") != null) { // 读取加设图图纸信息 塞入图纸set中
						String JobcardInstallNo = null;
						try {

							JobcardInstallNo = index.get("moduleName") + "-" + index.get("workPackageNo") + "-"
									+ index.get("assemblyFabricationDetailNo").substring(0, 10);

							fabricationDrawingMap.put("JobcardInstallNo", JobcardInstallNo);
						} catch (Exception e) {
							// TODO: handle exception
						}
						shopDrawingMap = new HashMap<String, String>();
						shopDrawingMap.put("shopDrawingRev", index.get("shopDrawingRev"));
						shopDrawingMap.put("shopDrawingNo", index.get("shopDrawingNo"));
						shopDrawingMap.put("moduleName", index.get("moduleName"));
						shopDrawingMap.put("workPackageNo", index.get("workPackageNo"));
						shopDrawingMap.put("JobcardInstallNo", JobcardInstallNo);
						shopDrawings.add(shopDrawingMap);

						DrawingMaterial data = this.setDrawingMaterial(index, index.get("shopDrawingNo"),
								index.get("shopDrawingRev"), "ST", "shopDrawing");
						if (drawingMaterialsMap.get(index.get("shopDrawingNo") + index.get("shopDrawingRev")) == null) {
							drawingMaterialsMap.put(index.get("shopDrawingNo") + index.get("shopDrawingRev"), data);
						} else {
							drawingMaterialsMap.get(index.get("shopDrawingNo") + index.get("shopDrawingRev"))
									.getMaterials().addAll(data.getMaterials());
						}

					}

					if (index.get("nestingDrawingNo") != null) {// 套料图
						if (index.get("nestingDrawingNo").length() > 13 && index.get("nestingDrawingRev") != null) {
							nestingDrawingMap = new HashMap<String, String>();
							nestingDrawingMap.put("nestingDrawingNo", index.get("nestingDrawingNo"));
							nestingDrawingMap.put("nestingDrawingRev", index.get("nestingDrawingRev"));
							nestingDrawingMap.put("moduleName", index.get("moduleName"));
							nestingDrawingMap.put("workPackageNo", index.get("workPackageNo"));
							nestingDrawings.add(nestingDrawingMap);
							DrawingMaterial data = this.setDrawingMaterial(index, index.get("nestingDrawingNo"),
									index.get("nestingDrawingRev"), "ST", "nestingDrawing");

							if (drawingMaterialsMap
									.get(index.get("nestingDrawingNo") + index.get("nestingDrawingRev")) == null) {
								drawingMaterialsMap.put(index.get("nestingDrawingNo") + index.get("nestingDrawingRev"),
										data);
							} else {
								drawingMaterialsMap.get(index.get("nestingDrawingNo") + index.get("nestingDrawingRev"))
										.getMaterials().addAll(data.getMaterials());
							}
						}
					}

				}

			}

			Integer projectNumber = projectInfoMapper.select_ProjectNumber(jobNo);
			insertMaterials(materials, "ST", "bulk", projectNumber);// 插入母材物料
			insertMaterials(partss, "ST", "part", projectNumber); // 插入零件
			insertMaterials(remnantParts, "ST", "remnant", projectNumber);// 插入余料
			insertMaterials(assemblyFabricationDetails, "ST", "fabrication", projectNumber);// 插入构件

			List<DrawingMaterial> drawingList = insertdrawingMaterials(drawingMaterialsMap, "ST", projectNumber);// 插入图纸物料关联关系信息
			uxpmStck.UPDATE_SEQUENCE_UxpmstckMaxID();// 将系统ID与表中ID同步
			// // 提交
			for (DrawingMaterial index : drawingList) {
				if (index.getRev() == null) {
					System.err.println(index);
				}
			}

			Iterator<Map<String, String>> it = nestingDrawings.iterator();
			while (it.hasNext()) {
				Map<String, String> index = it.next();
				for (DrawingMaterial index2 : drawingList) {
					if (index2.getDrawing_No().equals(index.get("ShopDrawingNo"))
							&& index2.getRev().equals(index.get("shopDrawingRev"))) {
						it.remove();
					}
				}
			}

			// 插入错误图纸信息
			uxenglstMapper.delete_Uxmd();
			uxenglstMapper.delete_uxmd_PERM();
			// // 提交
			Integer Id = uxenglstMapper.select_UxmdMaxId();
			if (Id == null) {
				Id = 1;
			} else {
				Id++;
			}
			for (int i = 0; i < drawingList.size() / 30 + 1; i++) {// 插入错误图纸信息
				List<DrawingMaterial> index = new ArrayList<DrawingMaterial>();
				if ((i + 1) * 30 > drawingList.size())
					index = drawingList.subList(i * 30, drawingList.size());
				if ((i + 1) * 30 <= drawingList.size())
					index = drawingList.subList(i * 30, (i + 1) * 30);

				if (index.size() != 0) {
					uxenglstMapper.insert_Uxmd(index, Id, projectNumber);
					uxenglstMapper.insert_Uxmd_PERM(index, Id);
					//
				}
			}
			// uxenglstMapper.UPDATE_SEQUENCE_UxpmstckMaxID();// 将系统ID与表中ID同步

			List<SchedulePlanEngineering> setemps = this.deweightDrawing(shopDrawings, nestingDrawings,
					fabricationDrawings, "ST", jobNo);// 图纸去重

			this.insertDrawing(setemps, jobNo); // 插入图纸
		}
	}

	public void AnalyzeWeldListExcelST() throws IOException {

		List<Map<String, String>> projectInfoMaps = projectInfoMapper.select_ProjectID_Number(); // 查找出所有项目

		for (Map<String, String> projectInfoMap : projectInfoMaps) { // 遍历项目

			Object object = projectInfoMap.get("PID");
			int projectId = Integer.parseInt(String.valueOf(object));
			List<String> filePaths = this.inquire_ProjectWeldFilePath(projectId, "ST");

			// String path = "F:/test/ST/MERO2/weld/";
			// List<String> fileNames = this.traverseFolder(path);
			for (String filePath : filePaths) {

				// List<Map<String, String>> data =
				// AnalyzeServer.AnalyzeWeldersListforStructureExcelST(path + fileName);
				List<Map<String, String>> data = AnalyzeServer.AnalyzeWeldersListforStructureExcelST(filePath);
				Integer id = weldingListMapper.select_WeldingList_MAXId_ST();
				if (id == null) {
					id = 1;
				} else {
					id++;

				}

				List<String> list = weldingListMapper.select_WeldingList_List_ST(projectId);
				List<Map<String, String>> datas = data.stream()
						.filter(it -> !list.contains(it.get("AssemblyNo") + it.get("DrawingRev") + it.get("WeldNo")))
						.collect(Collectors.toList());

				for (int i = 0; i < datas.size() / 800 + 1; i++) {// 一次提交所有数据等待时间太久 分割开来提交
					List<Map<String, String>> index = new ArrayList<Map<String, String>>();
					if ((i + 1) * 800 > datas.size())
						index = datas.subList(i * 800, datas.size());
					if ((i + 1) * 800 <= datas.size())
						index = datas.subList(i * 800, (i + 1) * 800);
					if (index.size() != 0) {
						weldingListMapper.insert_WeldingList_ST(index, id, projectId);
						weldingListMapper.insert_WeldingList_PERM_ST(index, id);
						id = id + index.size();
					}
				}
			}
		}
	}

	/**
	 * 解析电仪专业
	 */
	@Override
	public void AnalyzeMTRExcelEI() throws IOException {
		List<String> fileNames = this.traverseFolder("F:/test/物料表格/EI");
		Set<Map<String, String>> shopDrawings = new HashSet<Map<String, String>>();// 加设图纸
		Set<Map<String, String>> materials = new HashSet<Map<String, String>>(); // 母材信息
		Set<Map<String, String>> partss = new HashSet<Map<String, String>>();// 零件
		Set<Map<String, String>> assemblyFabricationDetails = new HashSet<Map<String, String>>();// 构件
		Map<String, String> shopDrawingMap = null;
		Map<String, String> material = null;
		Map<String, String> parts = null;
		Map<String, String> assemblyFabricationDetail = null;

		Map<String, DrawingMaterial> drawingMaterialsMap = new HashMap<String, DrawingMaterial>();
		Set<Material2> material2s = new HashSet<Material2>();
		String jobNo = null;
		for (String fileName : fileNames) {
			System.err.println(fileName);
			List<List<Map<String, String>>> list = AnalyzeServer.AnalyzeExcelEI("F:/test/物料表格/EI/" + fileName);
			for (Map<String, String> index : list.get(0)) {

				if (jobNo == null) {
					jobNo = index.get("jobNo");
				}

				if (index.get("shopDrawingNo") != null) { // 读取加设图图纸信息 塞入图纸set中
					if (index.get("shopDrawingNo").length() > 32) {
						String[] shopDrawingNos = index.get("shopDrawingNo").split("/");
						for (int i = 0; i < shopDrawingNos.length; i++) {
							shopDrawingMap = new HashMap<String, String>();
							shopDrawingMap.put("shopDrawingRev", index.get("shopDrawingRev"));
							shopDrawingMap.put("moduleName", index.get("moduleName"));
							shopDrawingMap.put("workPackageNo", index.get("workPackageNo"));
							if (shopDrawingNos[i].length() < 32) {
								shopDrawingMap.put("shopDrawingNo",
										shopDrawingNos[0].substring(0,
												shopDrawingNos[0].length() - shopDrawingNos[i].length())
												+ shopDrawingNos[i]);
							} else {
								shopDrawingMap.put("shopDrawingNo", shopDrawingNos[i]);
							}
							shopDrawings.add(shopDrawingMap);

							DrawingMaterial data = this.setDrawingMaterial(index, shopDrawingMap.get("shopDrawingNo"),
									shopDrawingMap.get("shopDrawingRev"), "EI", "shopDrawingNo");
							if (drawingMaterialsMap.get(shopDrawingMap.get("shopDrawingNo")
									+ shopDrawingMap.get("shopDrawingRev")) == null) {
								drawingMaterialsMap.put(
										shopDrawingMap.get("shopDrawingNo") + shopDrawingMap.get("shopDrawingRev"),
										data);
							} else {
								drawingMaterialsMap
										.get(shopDrawingMap.get("shopDrawingNo") + shopDrawingMap.get("shopDrawingRev"))
										.getMaterials().addAll(data.getMaterials());
							}

						}
					} else {
						shopDrawingMap = new HashMap<String, String>();
						shopDrawingMap.put("shopDrawingRev", index.get("shopDrawingRev"));
						shopDrawingMap.put("shopDrawingNo", index.get("shopDrawingNo"));
						shopDrawingMap.put("moduleName", index.get("moduleName"));
						shopDrawingMap.put("workPackageNo", index.get("workPackageNo"));
						shopDrawings.add(shopDrawingMap);

						DrawingMaterial data = this.setDrawingMaterial(index, shopDrawingMap.get("shopDrawingNo"),
								shopDrawingMap.get("shopDrawingRev"), "EI", "shopDrawingNo");
						if (drawingMaterialsMap.get(
								shopDrawingMap.get("shopDrawingNo") + shopDrawingMap.get("shopDrawingRev")) == null) {
							drawingMaterialsMap.put(
									shopDrawingMap.get("shopDrawingNo") + shopDrawingMap.get("shopDrawingRev"), data);
						} else {
							drawingMaterialsMap
									.get(shopDrawingMap.get("shopDrawingNo") + shopDrawingMap.get("shopDrawingRev"))
									.getMaterials().addAll(data.getMaterials());
						}
					}
				}

				// 母材信息塞入
				if (index.get("materialCode") != null && !index.get("materialCode").equals("NA")
						&& !index.get("materialCode").equals(" ")) {
					material = new HashMap<String, String>();
					material.put("materialCode", index.get("materialCode"));
					material.put("OldMaterialPartCode", index.get("materialCode2"));
					material.put("grade", index.get("grade")); // 材质
					material.put("unit", index.get("unit"));// 单位
					materials.add(material);

				}
				// 零件信息
				if (index.get("partNo") != null) {
					parts = new HashMap<String, String>();
					parts.put("partNo", index.get("partNo"));// 零件编号
					parts.put("materialCode", index.get("materialCode"));
					parts.put("unit", index.get("unit"));// 计量单位
					parts.put("grade", index.get("grade")); // 材质
					parts.put("steelType", index.get("steelType")); // 零件类型
					parts.put("partProfile", index.get("partName")); // 零件规格
					parts.put("partName", index.get("partName")); // 零件名称
					parts.put("materialCode", index.get("materialCode"));// 母材编号
					partss.add(parts);

				}
				// 构件信息
				if (index.get("assemblyFabricationDetailNo") != null
						&& !index.get("assemblyFabricationDetailNo").equals("")
						&& !index.get("assemblyFabricationDetailNo").equals("NA")) {
					assemblyFabricationDetail = new HashMap<String, String>();
					assemblyFabricationDetail.put("assemblyFabricationDetailNo",
							index.get("assemblyFabricationDetailNo"));// 构件编码
					assemblyFabricationDetails.add(assemblyFabricationDetail);
				}

			}
		}
		Integer projectNumber = projectInfoMapper.select_ProjectNumber(jobNo);

		this.insertMaterials(materials, "EI", "bulk", projectNumber); // 插入母材物料
		this.insertMaterials(partss, "EI", "part", projectNumber); // 插入零件
		this.insertMaterials(assemblyFabricationDetails, "EI", "fabrication", projectNumber);// 插入构件

		// 图纸关联物料信息 // 插入物料与图纸的对应关系
		this.insertdrawingMaterials(drawingMaterialsMap, "EI", projectNumber);
		uxpmStck.UPDATE_SEQUENCE_UxpmstckMaxID();// 将系统ID与表中ID同步
		// 提交
		// UxenglstMapper uxenglstMapper = null.getMapper(UxenglstMapper.class);

		// List<SchedulePlanEngineering> setemps = this.deweightDrawing( shopDrawings,
		// null, null, "EI"); // 封装并去重

		// this.insertDrawing(setemps); // 插入图纸

	}

	/**
	 * 解析管线专业
	 */
	@Override
	public void AnalyzeMTRExcelPI() throws IOException {

		String path = "F:/test/管线专业";
		List<String> fileNames = this.traverseFolder(path);
		for (String fileName : fileNames) {
			List<List<Map<String, String>>> list = AnalyzeServer.AnalyzeExcelPI(path + "/" + fileName);
			
			Set<Map<String, String>> shopDrawings = new HashSet<Map<String, String>>();// 加设图纸
			Set<Map<String, String>> nestingDrawings = new HashSet<Map<String, String>>();// 加设图纸
			Set<Map<String, String>> materials = new HashSet<Map<String, String>>(); // 母材信息
			Set<Map<String, String>> partss = new HashSet<Map<String, String>>();// 零件
			Set<Map<String, String>> remnantParts = new HashSet<Map<String, String>>();// 余料
			Set<Map<String, String>> fabricationDrawings = new HashSet<Map<String, String>>();// 构件图
			Set<Map<String, String>> assemblyFabricationDetails = new HashSet<Map<String, String>>();// 构件
			Map<String, String> assemblyFabricationDetail = null;
			Map<String, String> shopDrawingMap = null;
			Map<String, String> material = null;
			Map<String, String> remnantPart = null;
			Map<String, String> parts = null;
			Map<String, String> fabricationDrawingMap = null;
			Map<String, String> nestingDrawingMap = null;
			Map<String, DrawingMaterial> drawingMaterialsMap = new HashMap<String, DrawingMaterial>();
			String jobNo = null;
			for (Map<String, String> index : list.get(0)) {
				if (jobNo == null) {
					jobNo = index.get("jobNo");
				}

				// 母材信息塞入
				if (index.get("materialCode") != null && !index.get("materialCode").equals("NA")
						&& !index.get("materialCode").equals(" ")) {
					material = new HashMap<String, String>();
					material.put("materialCode", index.get("materialCode"));
					material.put("OldMaterialPartCode", index.get("materialCode2"));
					material.put("grade", index.get("grade")); // 材质
					material.put("materialLongDescription", index.get("materialLongDescription"));// 长描述
					material.put("unit", index.get("unit"));// 单位
					materials.add(material);

				}
				// 零件信息
				if (index.get("partNo") != null) {
					String fabricationDrawingNo = index.get("shopDrawingNo") + "-" + index.get("shopDrawingRev") + "-"
							+ index.get("FabricationNo");
					parts = new HashMap<String, String>();
					parts.put("discipline", "PI"); // 专业
					parts.put("partNo", index.get("partNo"));// 零件编号
					parts.put("materialCode", index.get("materialCode"));
					parts.put("unit", index.get("unit"));// 计量单位
					parts.put("grade", index.get("grade")); // 材质
					parts.put("partType", index.get("partType")); // 零件类型
					parts.put("workPackageNo", index.get("workPackageNo"));// 工作包
					parts.put("netSingleLength", index.get("qty")); // 零件净长度
					parts.put("netSingleWeight", index.get("unitNetWeight")); // 零件单净重
					parts.put("partName", index.get("partName")); // 零件名称
					parts.put("qty", index.get("qty"));
					parts.put("partType", index.get("partType"));
					parts.put("remnantPartNo", index.get("remnantPartNo")); // 余料信息
					parts.put("materialCode", index.get("materialCode"));// 母材编号
					parts.put("materialCode2", index.get("materialCode2"));// 母材编号
					parts.put("materialLongDescription", index.get("materialLongDescription"));// 长描述
					parts.put("assemblyFabricationDetailNo", fabricationDrawingNo);// 构件编码 也是预制图版本
					parts.put("assemblyFabricationDetailRev", index.get("shopDrawingRev")); // 版本
					parts.put("nestingDrawingNo", index.get("nestingDrawingNo")); // 套料图
					parts.put("nestingDrawingRev", index.get("nestingDrawingRev"));// 套料图版本
					parts.put("Part_Main_Size", index.get("partMainSize"));// 套料图版本
					parts.put("Ident_Code", index.get("identCode"));// 套料图版本
					partss.add(parts);

				}

				// 构件信息 SPOOL
				if (index.get("FabricationNo") != null && !index.get("FabricationNo").equals("")
						&& !index.get("FabricationNo").equals("NA") && !index.get("shopDrawingRev").equals(null)) {
					String fabricationDrawingNo = index.get("shopDrawingNo") + "-" + index.get("shopDrawingRev") + "-"
							+ index.get("FabricationNo");
					assemblyFabricationDetail = new HashMap<String, String>();
					assemblyFabricationDetail.put("assemblyFabricationDetailNo", fabricationDrawingNo);// 构件编码
					assemblyFabricationDetail.put("qty", index.get("qty"));
					assemblyFabricationDetail.put("unit", index.get("unit"));// 计量单位
					assemblyFabricationDetail.put("grade", index.get("grade")); // 材质
					assemblyFabricationDetails.add(assemblyFabricationDetail);

					fabricationDrawingMap = new HashMap<String, String>();
					fabricationDrawingMap.put("lineNo", index.get("lineNo"));
					fabricationDrawingMap.put("FabricationDrawingNo", fabricationDrawingNo);
					fabricationDrawingMap.put("FabricationDrawingNoRev", index.get("shopDrawingRev"));
					fabricationDrawingMap.put("moduleName", index.get("moduleName"));
					// fabricationDrawingMap.put("workPackageNo", index.get("workPackageNo"));
					fabricationDrawingMap.put("JobcardInstallNo",
							index.get("shopDrawingNo") + index.get("shopDrawingRev"));
					fabricationDrawings.add(fabricationDrawingMap);

					DrawingMaterial data = this.setDrawingMaterialPI(index, fabricationDrawingNo,
							index.get("shopDrawingRev"), "PI", "fatherDrawing");
					if (drawingMaterialsMap.get(fabricationDrawingNo + index.get("shopDrawingRev")) == null) {
						drawingMaterialsMap.put(fabricationDrawingNo + index.get("shopDrawingRev"), data);
					} else {
						drawingMaterialsMap.get(fabricationDrawingNo + index.get("shopDrawingRev")).getMaterials()
								.addAll(data.getMaterials());
					}

				}
				// 余料
				if (index.get("remnantPartNo") != null && !index.get("remnantPartNo").equals("")
						&& !index.get("remnantPartNo").equals("整料") && !index.get("remnantPartNo").equals("NA")) {
					remnantPart = new HashMap<String, String>();
					remnantPart.put("remnantPartNo", index.get("remnantPartNo"));
					remnantPart.put("unit", index.get("unit"));// 计量单位
					remnantPart.put("grade", index.get("grade")); // 材质
					remnantPart.put("materialCode", index.get("materialCode"));// 母材编号
					remnantParts.add(remnantPart);
				}

				if (index.get("shopDrawingNo") != null) { // 读取加设图图纸信息 塞入图纸set中
					shopDrawingMap = new HashMap<String, String>();
					shopDrawingMap.put("shopDrawingRev", index.get("shopDrawingRev"));
					shopDrawingMap.put("shopDrawingNo", index.get("shopDrawingNo"));
					shopDrawingMap.put("lineNo", index.get("lineNo"));
					shopDrawingMap.put("moduleName", index.get("moduleName"));
					shopDrawingMap.put("workPackageNo", index.get("workPackageNo"));
					shopDrawings.add(shopDrawingMap);
					DrawingMaterial data = this.setDrawingMaterialPI(index, index.get("shopDrawingNo"),
							index.get("shopDrawingRev"), "PI", "shopDrawing");
					if (drawingMaterialsMap.get(index.get("shopDrawingNo") + index.get("shopDrawingRev")) == null) {
						drawingMaterialsMap.put(index.get("shopDrawingNo") + index.get("shopDrawingRev"), data);
					} else {
						drawingMaterialsMap.get(index.get("shopDrawingNo") + index.get("shopDrawingRev")).getMaterials()
								.addAll(data.getMaterials());
					}
				}

				if (index.get("nestingDrawingNo2") != null && !index.get("nestingDrawingNo2").equals("未套料")) {// 套料图
					nestingDrawingMap = new HashMap<String, String>();
					nestingDrawingMap.put("nestingDrawingNo", index.get("nestingDrawingNo"));
					nestingDrawingMap.put("nestingDrawingRev", index.get("nestingDrawingRev"));
					nestingDrawingMap.put("moduleName", index.get("moduleName"));
					nestingDrawingMap.put("workPackageNo", index.get("workPackageNo"));
					nestingDrawings.add(nestingDrawingMap);

					DrawingMaterial data = this.setDrawingMaterialPI(index, index.get("nestingDrawingNo"),
							index.get("nestingDrawingRev"), "PI", "nestingDrawing");
					if (drawingMaterialsMap
							.get(index.get("nestingDrawingNo") + index.get("nestingDrawingRev")) == null) {
						drawingMaterialsMap.put(index.get("nestingDrawingNo") + index.get("nestingDrawingRev"), data);
					} else {
						drawingMaterialsMap.get(index.get("nestingDrawingNo") + index.get("nestingDrawingRev"))
								.getMaterials().addAll(data.getMaterials());
					}
				}

			}

			Integer projectNumber = projectInfoMapper.select_ProjectNumber(jobNo);

			this.insertMaterials(materials, "PI", "bulk", projectNumber); // 插入母材物料
			this.insertMaterials(partss, "PI", "part", projectNumber); // 插入零件
			this.insertMaterials(remnantParts, "PI", "remnant", projectNumber);// 插入余料
			this.insertMaterials(assemblyFabricationDetails, "PI", "fabrication", projectNumber);// 插入构件
			// 图纸关联物料信息 // 插入物料与图纸的对应关系
			this.insertdrawingMaterialsPI(drawingMaterialsMap, "PI", projectNumber);

			// 插入物料与图纸的对应关系
			System.err.println(fabricationDrawings);
			List<SchedulePlanEngineering> setemps = this.deweightDrawing(shopDrawings, null, fabricationDrawings, "PI",
					jobNo);

			this.insertDrawing(setemps, jobNo); // 插入图纸
		}
	}

	public void AnalyzeWeldListExcelPI() throws IOException {
		List<Map<String, String>> data = AnalyzeServer.AnalyzeWeldersListforStructureExcelPI(
				"F:/test/管线专业/Welding List/Welding List Template for Piping-TS130.xlsx");

		Integer projectNumber = projectInfoMapper.select_ProjectNumber(data.get(0).get("projectNo"));

		List<String> list = weldingListMapper.select_WeldingList_List_PI(projectNumber);
		List<Map<String, String>> datas = data.stream().filter(it -> !list.contains(it.get("assembly_Drawing_No")))
				.collect(Collectors.toList());

		Integer id = weldingListMapper.select_WeldingList_MAXId_PI();
		if (id == null) {
			id = 1;
		} else {
			id++;
		}

		for (int i = 0; i < datas.size() / 500 + 1; i++) {// 一次提交所有数据等待时间太久 分割开来提交
			List<Map<String, String>> index = new ArrayList<Map<String, String>>();
			if ((i + 1) * 500 > datas.size())
				index = datas.subList(i * 500, datas.size());
			if ((i + 1) * 500 <= datas.size())
				index = datas.subList(i * 500, (i + 1) * 500);
			if (index.size() != 0) {
				weldingListMapper.insert_WeldingList_PI(index, id, projectNumber);
				weldingListMapper.insert_WeldingList_PERM_PI(index, id);
				id = id + index.size();
			}
		}
	}

	/**
	 * 管线专业试压包
	 * 
	 * @throws IOException
	 * @throws FileNotFoundException
	 */
	public void AnalyzePressurePackagePI() throws FileNotFoundException, IOException {
		Set<Map<String, String>> pressureTestPackages = new HashSet<Map<String, String>>();// 试压包信息
		Map<String, String> pressureTestPackage = null;
		Set<Map<String, String>> spools = new HashSet<Map<String, String>>(); // spool信息
		Map<String, String> spool = new HashMap<String, String>(); //
		Set<Map<String, String>> isos = new HashSet<Map<String, String>>(); // iso图信息
		Map<String, String> iso = new HashMap<String, String>(); //

		List<String> fileNames = this.traverseFolder("F:/test/试压包");
		String jobNo = null;

		List<String> testPackNos = null;
		List<String> newTestPackNos = new ArrayList<String>();
		Integer projectNumber = null;

		for (String fileName : fileNames) {
			List<Map<String, String>> list = AnalyzeServer.AnalyzePressurePackagePI("F:/test/试压包/" + fileName);
			for (Map<String, String> index : list) {

				if (jobNo == null) {
					jobNo = index.get("jobNo");
					if (testPackNos == null) {
						if (projectNumber == null) {
							projectNumber = projectInfoMapper.select_ProjectNumber(jobNo);
						}
					}
					testPackNos = uxtpMapper.select_unifier_Uxtp_testPackNo(projectNumber);
				}
				String testPackNo = index.get("testPackNo");

				if (testPackNo != null) {
					if (!testPackNos.contains(testPackNo) && !testPackNo.equals("NA") && !testPackNo.equals(" ")
							&& !testPackNo.equals("")) {
						System.err.println(testPackNo);
						newTestPackNos.add(testPackNo);
						pressureTestPackage = new HashMap<String, String>();
						pressureTestPackage.put("testPackNo", testPackNo); // 试压包号
						pressureTestPackage.put("systemNo", index.get("systemNo"));// 系统号
						pressureTestPackage.put("moduleNo", index.get("moduleName"));// 模块号
						pressureTestPackage.put("subSystemNo", index.get("subSystemNo"));// 系统子号
						pressureTestPackage.put("fluidCode", index.get("fluidCode"));// 系统代码
						pressureTestPackage.put("testPressure", index.get("testPressure"));// 测试压力
						pressureTestPackage.put("testMedium ", index.get("testMedium"));// 试压介质
						pressureTestPackage.put("holdingTime", index.get("holdingTime"));// 稳压时间
						pressureTestPackages.add(pressureTestPackage);

						String ISONo = index.get("ISONo");
						String ISOLastRev = index.get("ISOLastRev");
						String spoolNo = index.get("spoolNo");
						String spoolLastRev = index.get("spoolLastRev");
						if (!ISONo.equals(null) && !ISOLastRev.equals(null) && !spoolNo.equals(null)
								&& !spoolLastRev.equals(null)) {
							spool = new HashMap<String, String>();
							iso = new HashMap<String, String>(); //
							spool.put("testPackNo", testPackNo); // 试压包号
							spool.put("pIdNo", index.get("pIdNo")); // P&ID
							spool.put("pIdNoRev", index.get("pIdNoRev")); // P&ID版本
							spool.put("pIdLineNo", index.get("pIdLineNo")); // P&ID管线号
							spool.put("pipingMateiralClass", index.get("pipingMateiralClass")); // 管线材料等级
							spool.put("pipingMateiral", index.get("pipingMateiral")); // 管线材料
							spool.put("spoolNo", ISONo + "-" + ISOLastRev + "-" + spoolNo); // spool编码
							spool.put("spoolLastRev", spoolLastRev);// spool版本号
							spool.put("spoolDia", index.get("spoolDia")); // 管段尺寸
							spool.put("spoolVolume", index.get("spoolVolume")); // 体积
							spool.put("operationPressure", index.get("operationPressure")); // 操作压力(kPa)
							spool.put("designPressure", index.get("designPressure")); // 设计压力(kPa)
							spool.put("testPackageHSIORITY", index.get("testPackageHSIORITY")); // 试压优先级别
							spool.put("UUU_TAB_ID", "0");
							spools.add(spool);
							iso.put("testPackNo", testPackNo); // 试压包号
							iso.put("ISO_No", ISONo);
							iso.put("UUU_TAB_ID", "2");

							iso.put("ISOLastRev", ISOLastRev);
							isos.add(iso);
						}
					}
				}
			}
		}

		if (pressureTestPackages.size() > 0) {
			List<Map<String, String>> isosList = UxJbcardMapper.select_PressurePackage_ISO_STATUS(projectNumber, isos);

			for (Map<String, String> index : isos) {
				for (Map<String, String> ios : isosList) {
					if (index.get("ISO_No").equals(ios.get("ISO_No"))
							&& index.get("ISOLastRev").equals(ios.get("ISOLastRev"))) {
						index.putAll(iso);
					}
				}

			}

			if (newTestPackNos.size() > 0) {// 如果表格中有新的试压包信息则录入信息
				Integer maxId = uxtpMapper.select_unifier_Uxtp_MaxId();
				if (maxId == null) {
					maxId = 1;
				} else {
					maxId++;
				}
				System.err.println(pressureTestPackages);
				List<Map<String, String>> indexs = new ArrayList<Map<String, String>>(pressureTestPackages);
				for (int i = 0; i < indexs.size() / 900 + 1; i++) {// 一次提交所有数据等待时间太久 分割开来提交
					List<Map<String, String>> index = new ArrayList<Map<String, String>>();
					if ((i + 1) * 900 > indexs.size())
						index = indexs.subList(i * 900, indexs.size());
					if ((i + 1) * 900 <= indexs.size())
						index = indexs.subList(i * 900, (i + 1) * 900);
					if (index.size() > 0) {
						uxtpMapper.insert_unifier_Uxtp(index, projectNumber, maxId);
						uxtpMapper.insert_unifier_Uxtp_PERM(index, maxId);
						maxId = maxId + index.size();
					}
				}

				maxId = uxtpMapper.select_unifier_Uxtp_lieitem_MaxId();

				List<Map<String, Object>> TestPackNoObjects = uxtpMapper
						.select_unifier_Uxtp_testPackNo_dataId(projectNumber, newTestPackNos);
				spools.addAll(isos);// 合并所有行项
				for (Map<String, String> index : spools) {
					for (Map<String, Object> TestPackNoObject : TestPackNoObjects) {
						if (index.get("testPackNo").equals(String.valueOf(TestPackNoObject.get("TEST_PACKAGE_NO")))) {
							index.put("RECORD_ID", String.valueOf(TestPackNoObject.get("ID")));
						}
					}
				}

				if (maxId == null) {
					maxId = 1;
				} else {
					maxId++;
				}
				indexs = new ArrayList<Map<String, String>>(spools);
				for (int i = 0; i < indexs.size() / 900 + 1; i++) {// 一次提交所有数据等待时间太久 分割开来提交
					List<Map<String, String>> index = new ArrayList<Map<String, String>>();
					if ((i + 1) * 900 > indexs.size())
						index = indexs.subList(i * 900, indexs.size());
					if ((i + 1) * 900 <= indexs.size())
						index = indexs.subList(i * 900, (i + 1) * 900);
					if (index.size() > 0) {
						uxtpMapper.insert_unifier_Uxtp_lieitem(index, maxId);
						uxtpMapper.updateJobcard_testPackNo(index, projectNumber);// 为每个spool 添加更新试压包编号
						uxtpMapper.updateUxenglst_testPackNo(index, projectNumber);// 修改图纸清单为每个spool图 添加更新试压包编号
						maxId = maxId + index.size();
					}
				}

			}
		}
	}

	/**
	 * 解析设备专业现在已完成读取表格获取数据，并且讲表格内容加入到 图纸清单和母材表中
	 * 
	 * @throws IOException
	 */
	public void AnalyzeMTRExcelMA() throws IOException {
		Set<Map<String, String>> shopDrawings = new HashSet<Map<String, String>>();// 加设图纸
		Set<Map<String, String>> partss = new HashSet<Map<String, String>>();// 零件
		Set<Map<String, String>> materials = new HashSet<Map<String, String>>(); // 母材信息
		Set<Map<String, String>> equipmentLayouts = new HashSet<Map<String, String>>(); // 母材信息
		Map<String, DrawingMaterial> drawingMaterialsMap = new HashMap<String, DrawingMaterial>();
		Map<String, String> material = null;
		Map<String, String> shopDrawingMap = null;
		Map<String, String> equipmentLayout = null;
		Map<String, String> parts = null;

		List<String> fileNames = this.traverseFolder("F:/test/设备专业/MTR");
		String jobNo = null;
		for (String fileName : fileNames) {
			List<List<Map<String, String>>> list = AnalyzeServer.AnalyzeExcelMA("F:/test/设备专业/MTR/" + fileName);
			for (Map<String, String> index : list.get(0)) {
				if (jobNo == null) {
					jobNo = index.get("jobNo");
				}
				String drawing = index.get("GADrawingNo") + "-" + index.get("tagNo");
				String shopDrawingRev = index.get("GADrawingRev");
				if (drawing != null) { // 图纸关联设备信息
					shopDrawingMap = new HashMap<String, String>();
					shopDrawingMap.put("shopDrawingRev", shopDrawingRev);
					shopDrawingMap.put("shopDrawingNo", drawing);
					shopDrawingMap.put("moduleName", index.get("moduleName"));
					if (index.get("Location") != null) {
						shopDrawingMap.put("loc", index.get("Level") + "-" + index.get("Location"));
					} else {
						shopDrawingMap.put("loc", index.get("Level"));
					}
					shopDrawingMap.put("installation_Method_PD", index.get("InstallationMethod"));
					shopDrawingMap.put("connection_Type_PD", index.get("ConnectionForm"));
					shopDrawingMap.put(fileName, jobNo);
					shopDrawings.add(shopDrawingMap);
					DrawingMaterial data = this.setDrawingMaterialMA(index, drawing, shopDrawingRev, "MA",
							"shopDrawing");

					if (drawingMaterialsMap.get(drawing + shopDrawingRev) == null) {
						drawingMaterialsMap.put(drawing + shopDrawingRev, data);
					} else {
						drawingMaterialsMap.get(drawing + shopDrawingRev).getMaterials().addAll(data.getMaterials());
					}
				}
				// 母材信息塞入
				String materialCode = index.get("materialCode");
				String tagNo = index.get("tagNo");
				if (index.get("type").equals("设备")) {
					// 设备信息塞入
					if (tagNo != null && !tagNo.equals("")) {
						equipmentLayout = new HashMap<String, String>();
						equipmentLayout.put("tagNo", index.get("tagNo"));
						equipmentLayout.put("materialCode", index.get("materialCode"));
						equipmentLayout.put("grade", index.get("Material")); // 材质
						equipmentLayout.put("unit", index.get("Unit"));// 单位
						equipmentLayout.put("materialName", index.get("equipmentName")); // 物料名称
						equipmentLayouts.add(equipmentLayout);
					}
				} else if (index.get("type").equals("附件")) {
					if (materialCode != null && !materialCode.equals("")) {
						parts = new HashMap<String, String>();
						parts.put("partNo", index.get("materialCode"));
						parts.put("grade", index.get("Material")); // 材质
						parts.put("unit", index.get("Unit"));// 单位
						parts.put("materialName", index.get("Description"));// 物料名称
						parts.put("materialCode", index.get("materialCode"));
						parts.put("tagNo", index.get("tagNo"));
						partss.add(parts);
					}
				} else if (index.get("type").equals("母材")) {
					if (materialCode != null && !materialCode.equals("")) {
						material = new HashMap<String, String>();
						material.put("materialCode", index.get("materialCode"));
						material.put("grade", index.get("Material")); // 材质
						material.put("unit", index.get("Unit"));// 单位
						material.put("materialName", index.get("Description"));// 物料名称
						materials.add(material);
					}
				}
			}

			Integer projectNumber = projectInfoMapper.select_ProjectNumber(jobNo);
			insertMaterials(materials, "MA", "bulk", projectNumber);// 插入母材物料
			insertMaterials(equipmentLayouts, "MA", "tag", projectNumber);// 插入设备物料
			insertMaterials(partss, "MA", "part", projectNumber); // 插入设备附件
			insertdrawingMaterialsMA(drawingMaterialsMap, "MA", projectNumber);// 插入图纸与物料的逻辑关系
			List<SchedulePlanEngineering> setemps = this.deweightDrawing(shopDrawings, null, null, "MA", jobNo);// 图纸去重
			this.insertDrawing(setemps, jobNo); // 插入图纸
		}

	}

	public void AnalyzeWeldListExcelMA() throws IOException {
		List<Map<String, String>> data = AnalyzeServer
				.AnalyzeWeldersListforStructureExcelMA("F:/test/设备专业/Welders List-TS001-TS002- 副本.xlsx");

		Integer projectNumber = projectInfoMapper.select_ProjectNumber(data.get(0).get("projectNo"));

		List<String> list = weldingListMapper.select_WeldingList_List_MA(projectNumber);
		List<Map<String, String>> datas = data.stream()
				.filter(it -> !list.contains(
						it.get("equipmentGADrawingNo") + it.get("equipmentGADrawingNoRev") + it.get("weldingNo")))
				.collect(Collectors.toList());

		Integer id = weldingListMapper.select_WeldingList_MAXId_MA();

		if (id == null) {
			id = 1;
		} else {
			id++;
		}

		for (int i = 0; i < datas.size() / 800 + 1; i++) {// 一次提交所有数据等待时间太久 分割开来提交
			List<Map<String, String>> index = new ArrayList<Map<String, String>>();
			if ((i + 1) * 800 > datas.size())
				index = datas.subList(i * 800, datas.size());
			if ((i + 1) * 800 <= datas.size())
				index = datas.subList(i * 800, (i + 1) * 800);
			if (index.size() != 0) {
				weldingListMapper.insert_WeldingList_MA(index, id, projectNumber);
				weldingListMapper.insert_WeldingList_PERM_MA(index, id);
				id = id + index.size();
			}
		}

	}

	public void test() {
		List<Map<String, String>> projectInfoMaps = projectInfoMapper.select_ProjectID_Number(); // 查找出所有项目

		for (Map<String, String> projectInfoMap : projectInfoMaps) { // 遍历项目

		 
			
			Object object = projectInfoMap.get("PID");
			int projectId = Integer.parseInt(String.valueOf(object));
			
			if(projectId!=1015) {	
				continue;
			}			
			
			List<String> filePaths = this.inquire_ProjectWeldFilePath(projectId, "ST");
			for (String filePath : filePaths) {
				System.err.println(filePath);

			}
		}

	}



}
